package com.godofgamblers.hotelmanagementsystem.handler;

import com.godofgamblers.hotelmanagementsystem.dto.OrderMes;
import com.godofgamblers.hotelmanagementsystem.pojo.*;
import com.godofgamblers.hotelmanagementsystem.service.CartService;
import com.godofgamblers.hotelmanagementsystem.service.UserService;
import com.godofgamblers.hotelmanagementsystem.service.User_LevelService;
import lombok.Data;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

/*

@author huanglang

@create_time 2019-10-10 19:24

Nothing is difficult but bugs

*/
@Controller
@Data
public class HomeHandler {
    @Autowired
    private User_LevelService user_levelService;
    @Autowired
    private CartService cartService;
    @Resource
    private UserService userService;

    @RequestMapping("/index")
    public String index() {
        return "index";
    }
   /* @RequestMapping("/login")
    public String login() {
        return "login";
    }*/
    @RequestMapping("/cart")
    public String cart(){
        return "front_cart";
    }

    //跳转后台主页
    @RequestMapping("/back_index")
    public String back_index() {
        return "back_index";
    }

    // 跳转个人中心提取在handler中读取session
    @RequestMapping("/front_percenter")
    public ModelAndView enterUserCenter(){
        ModelAndView modelAndView = new ModelAndView();
        Session session = SecurityUtils.getSubject().getSession();
        User user = (User) session.getAttribute("user");
        User_Level user_level = cartService.findUserLevel(user);

       User user1 =  userService.findUserByUserid(user.getUser_id());


        modelAndView.addObject("user",user);
        modelAndView.addObject("user_level",user_level);
        modelAndView.addObject("user1",user1);


        System.out.println(user);
        modelAndView.setViewName("front_percenter");
        return modelAndView;
    }

    //跳转预定页面
    @RequestMapping("/back_order")
    public String back_order() {
        return "back_order";
    }

//    //跳转系统设置
//    @RequestMapping("/back_setting")
//    public String back_setting() {
//        return "back_setting";
//    }

    //跳转营业查询
    @RequestMapping("/back_charts")
    public String back_charts() {
        return "back_charts";
    }

    //跳转开房操作
    @RequestMapping("/back_operate")
    public ModelAndView back_operate() {

        Order order =new Order();
        User user =new User();
        Order_item order_item = new Order_item();
        Room_Type room_type = new Room_Type();
        OrderMes orderMes = new OrderMes(order_item,order,room_type,user);
        ModelAndView modelAndView =new ModelAndView();
        modelAndView.addObject("OrderInfo",orderMes);
        modelAndView.setViewName("back_operate");
        return modelAndView;

    }


}
